<template>
  <div class="shop-list" v-infinite-scroll="load">
    <div class="shop-title">
      <span class="iconfont icon-woshishangjia"></span>
      <span class="title">附近商家</span>
    </div>
    <div class="shop-main">
      <router-link
        v-for="(shopItem, index) in shopArrList"
        class="items"
        :to="{ path: '/shop', query: { id: shopItem.id, geohash } }"
        :key="index"
      >
        <div class="shop-img">
          <img :src="shopItem.image_path" alt="" />
        </div>
        <div class="shop-content">
          <div class="shop-top item-all">
            <div class="shop-brandname">
              <span class="item-brand">品牌</span>
              <span class="item-name">{{ shopItem.name }}</span>
            </div>
            <span class="item-security">
              <i>保</i>
              <i>准</i>
              <i>票</i>
            </span>
          </div>
          <div class="shop-center item-all">
            <div class="shop-sales">
              <div class="iconfont">
                <el-rate
                  v-model="shopItem.rating"
                  disabled
                  text-color="#ff9900"
                >
                </el-rate>
              </div>
              <span style="color: #ff6000; padding-left: 0.1rem">{{
                &nbsp;shopItem.rating
              }}</span>
              <span class="sales-num">
                &nbsp;月售{{ shopItem.recent_order_num }}单</span
              >
            </div>
            <div class="small-box">
              <span class="common-mini mini-pro">蜂鸟专送</span>
              <span class="common-mini mini-time">准时达</span>
            </div>
          </div>
          <div class="shop-bottom item-all">
            <div class="instructions">
              <span>￥{{ shopItem.float_minimum_order_amount }}起送 / </span>
              <span>&nbsp;配送费约20元</span>
            </div>
            <div class="distance-time">
              <span>{{ shopItem.distance }} /</span>
              <span style="color: #3190e8">
                &nbsp;{{ shopItem.order_lead_time }}</span
              >
            </div>
          </div>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script>
import { shopList } from "../../service/getData";
import { imgBaseUrl } from "@/config/env.js";
import { mapState } from "vuex";
export default {
  data() {
    return {
      scoreNum: 4,
      shopArrList: [],
      offset: 0,
      restaurantCategoryId: undefined,
      imgBaseUrl: "",
    };
  },
  computed: { ...mapState(["latitude", "longitude", "geohash"]) },

  mounted() {
    this.imgBaseUrl = imgBaseUrl;
    this.initData();
  },
  methods: {
    async initData() {
      let res = await shopList(
        this.latitude,
        this.longitude,
        this.offset,
        this.restaurantCategoryId
      );

      let shopArrlist = [...res];
      shopArrlist.forEach((item) => {
        let { image_path } = item;
        if (image_path) {
          // item.image_path = require(`${this.imgBaseUrl}${image_path}`);
          // item.image_path = require("" + this.imgBaseUrl + image_path + "");
          item.image_path = this.imgBaseUrl + image_path;
        }
      });
      console.log(shopArrlist);
      this.shopArrList = [...this.shopArrList, ...shopArrlist];
    },
    load() {
      this.initData();
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../../style/mixin";

.shop-list {
  width: 100%;
  overflow-x: auto;
  margin: 0.5rem 0;
  background: white;
  padding-bottom: 0.5rem;
}
.shop-title {
  @include wh(100%, 1.8rem);
  margin-left: 0.5rem;
  display: flex;
  align-items: center;
  span:first-child {
    @include sc(1.3rem, #666666);
  }
  span {
    @include sc(0.5rem, #666666);
  }
}

.items {
  display: flex;
  border-bottom: 0.025rem solid $bc;
  padding: 0.7rem 0.4rem;
  // margin-bottom: 1rem;
  .shop-img {
    margin-right: 0.4rem;
    img {
      @include wh(2.7rem, 2.7rem);
    }
  }

  .shop-content {
    flex: auto;
    .item-all {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0.2rem 0;
      div {
        display: flex;
        align-items: center;
      }
      span {
        @include sc(0.4rem, black);
      }
      .item-brand {
        background: #ffd930;
        border-radius: 0.07rem;
        font-weight: 600;
        font-size: 0.5rem;
        @include sc(0.4rem, rgb(27, 18, 18));
        border-radius: 0.05rem;
        padding: 0 0.1rem;
        margin-right: 0.2rem;
      }
      // 名称
      .item-name {
        font-weight: 600;
        @include sc(0.5rem, black);
        padding-left: 0.1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 6rem;
        // height: 0.6rem;
      }
      // 保 准 票
      .item-security {
        transform: scale(0.8);
        margin-right: -0.2rem;
        i {
          color: #999;
          border: 0.025rem solid #f1f1f1;
        }
      }
      // 评分
      .iconfont {
        margin-left: 0.15rem;
      }
      // 备注
      .instructions {
        transform: scale(0.9);
        margin-left: -0.4rem;
      }
      // 时间 -  距离
      .distance-time {
        transform: scale(0.9);
        margin-right: -0.3rem;
      }
      // 准时达
      .small-box {
        // 缩小后位置会发生偏移
        transform: scale(0.8);
        // 重新定位
        margin-right: -0.4rem;
        display: flex;
        justify-content: center;
        align-items: center;
        .common-mini {
          font-size: 0.4rem;
          margin-left: 0.2rem;
          padding: 0.025rem;
          border-radius: 0.07rem;
        }
        .mini-pro {
          color: #fff;
          border: 0.025rem solid #3190e8;
          background-color: #3190e8;
        }
        .mini-time {
          color: #3190e8;
          border: 0.025rem solid #3190e8;
        }
      }
    }
  }
}
</style>
<style lang="scss">
.iconfont {
  .el-rate {
    // width: 3rem;
    // height: 0.8rem;
    .el-rate__item {
      .el-rate__icon {
        margin-right: 0;
        margin-left: -0.15rem;
      }

      i {
        font-size: 0.3rem;
      }
    }
  }
}
</style>
